package net.aynt.blog.lucene;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Timer;

import org.apache.commons.lang3.math.NumberUtils;

import com.ketayao.search.IndexHolder;

public class LuceneManager {
	
	public final static void initLuceneManager(Map<String, String> config) {
		
		long scheduleTime = 
				NumberUtils.toLong(config.get("lucene.scheduleTime"), 1000*60*5);
		
		LuceneTasker tasker = new LuceneTasker(config.get("lucene.path") ,scheduleTime);
		Timer timer = new Timer();
		// 从现在开始 1 秒钟之后，每隔 1 秒钟执行一次 job1
		timer.schedule(tasker, 0, tasker.getScheduleTime());
		
		File file = new File(config.get("lucene.path"));
		if (!file.exists()) {
			file.mkdir();
		}
		
		try {
			IndexHolder.init(file.getPath());
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
